<!DOCTYPE html>
<html>
	<head>
		<title>-列表</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!-- 所有的 css & js 资源 -->
		<link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
		<link rel="stylesheet" href="../../static/sa.css">
		<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
		<script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>
		<script src="https://unpkg.com/http-vue-loader@1.4.2/src/httpVueLoader.js"></script>
		<script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js"></script>
		<script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>
		<script src="../../static/sa.js"></script>
	</head>
	<body>
		<div class="vue-box" style="display: none;" :style="'display: block;'">
			<div class="c-panel">
				<!-- ------------- 检索参数 ------------- -->
				<div class="c-title">检索参数</div>
				<el-form ref="form" :model='p' @submit.native.prevent>
					<sa-item type="text" name="商品名称" v-model="p.goodName"></sa-item>
					<el-button type="primary" icon="el-icon-search" @click="f6()">查询</el-button>
					<br />
					<sa-item name="综合排序">
						<el-radio-group  class="s-radio-text">
							<el-radio :label="0">默认</el-radio>
						</el-radio-group>
					</sa-item>
				</el-form>
				<!-- ------------- 快捷按钮 ------------- -->
				<sa-item type="fast-btn" show="add,delete,export,reset"></sa-item>
				<!-- ------------- 数据列表 ------------- -->



				<el-table
						:data="dataList"
						ref="data-table"
						class="data-table"
						row-key="goodId"
						default-expand-all
						border
						stripe
						:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
					<sa-td type="selection"></sa-td>
					<sa-td name="商品名称" prop="goodName"></sa-td>
					<sa-td name="商品库存" prop="inventory" type="num"></sa-td>
					<sa-td name="商品单价" prop="price" type="money"></sa-td>
					<el-table-column label="操作" fixed="right">
						<template slot-scope="s">
							<el-button class="c-btn" type="primary" icon="el-icon-edit" @click="update(s.row)">修改</el-button>
							<el-button class="c-btn" type="danger" icon="el-icon-delete" @click="del(s.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<script>
			var app = new Vue({
				components: {
					"sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),  
					"sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue'),		
				},
				el: '.vue-box',
				data: {
					p: { // 查询参数
						goodName: '',		// 商品名称
					},
					dataList: [], // 数据集合 
				},
				methods: {
					// 刷新
					f5: function() {
						sa.ajax('/good/getAllGood',null,function(res){
							this.dataList = res.data; // 数据
							sa.f5TableHeight();		// 刷新表格高度 
						}.bind(this));
					},
					f6: function() {
						sa.ajax('/good/getGood/'+this.p.goodName,function(res){
							this.dataList = res.data; // 数据
							sa.f5TableHeight();		// 刷新表格高度
						}.bind(this));
					},
					// 修改
					update: function(data) {
						sa.showIframe('修改数据', 'good-add.html?id=' + data.goodId, '380px', '90%');
					},
					// 新增
					add: function(data) {
						sa.showIframe('新增数据', 'good-add.html?id=-1', '380px', '90%');
					},
					// 删除
					del: function(data) {
						sa.confirm('是否删除，此操作不可撤销', function() {
							sa.ajax('/good/deleteGood/' + data.goodId, function(res) {
								this.f5();
								sa.ok('删除成功');

							}.bind(this))
						}.bind(this));
					},
					// 批量删除
					deleteByIds: function() {
						// 获取选中元素的id列表 
						let selection = this.$refs['data-table'].selection;
						let ids = sa.getArrayField(selection, 'goodId');
						if(selection.length == 0) {
							return sa.msg('请至少选择一条数据')
						}
						// 提交删除 
						sa.confirm('是否批量删除选中数据？此操作不可撤销', function() {
							sa.ajax('/good/deleteGoodByIds', {ids: ids.join(',')}, function(res) {
								this.f5();
								sa.ok('删除成功');
							}.bind(this))
						}.bind(this));
					},
				},
				created: function() {
					this.f5();
					sa.onInputEnter();
				}
			})
		</script>
	</body>
</html>
